﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using PBOffice.BLL;
using PBOffice.Models;
public partial class custom_TreeControl : System.Web.UI.UserControl
{
    List<FileInfo> deptList = new FileInfoManager().GetAllFileInfo();

    protected void Page_Load(object sender, EventArgs e)
    {

        if (!IsPostBack)
        {
            foreach (FileInfo item in deptList)
            {
                if (item.ParentId == 0)
                {
                    if (item.FileType.FileTypeId == 1)
                    {
                        TreeNode tn = new TreeNode();
                        tn.Text = item.FileName;
                        tn.Value = item.FileId.ToString();

                        tn.ImageUrl =item.FileType.FileTypeImage;

                        this.TreeView1.Nodes.Add(tn);
                        InitTreeByList(tn);

                    }
                }
            }
        }
    }
    private void InitTreeByList(TreeNode TN)
    {
        foreach (FileInfo item in deptList)
        {
            if (item.ParentId.ToString() == TN.Value)
            {
                if (item.FileType.FileTypeId == 1)
                {
                    TreeNode tn = new TreeNode();
                    tn.Text = "&nbsp;"+ item.FileName;
                    tn.Value = item.FileId.ToString();
                    //tn.NavigateUrl = item.NodeURL;
                    tn.ImageUrl =item.FileType.FileTypeImage;
                    TN.ChildNodes.Add(tn);
                    InitTreeByList(tn);
                }
            }


        }
    }
}